package com.slt.developkitweb.controler;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.slt.developkitpersistent.dto.UserDto;
import com.slt.developkitpersistent.model.User;
import com.slt.developkitweb.annotation.ShowAPI;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.net.HttpCookie;
@ShowAPI
@RestController
public class TestController {
    @GetMapping(value = "ok")
    @ApiOperation("")
    public UserDto ok(HttpServletRequest request){
        return new UserDto();
    }

    @PostMapping(value = "test")
    @ApiOperation("")
    public User test(@RequestBody User user){
        return user;
    }
    public static void main(String[] args) {
        HttpRequest request = HttpUtil.createGet("http://localhost:8888/ok");
        // 设置Cookie。例如，要设置名为"token"，值为"abcd1234"的Cookie：
        request.cookie(new HttpCookie("name","slt"));
        HttpResponse response = request.execute();
    }

//    @ApiOperation(value = "测试缓存使用")
//    @PostMapping(value = "testRedis", produces = "application/json;charset=utf-8")
//    public CacheUserInfo testRedis(@RequestBody TestDecode testDecode) throws Exception {
//        Object value = redisTemplate.opsForValue().get("ENP_USER_OBJECT_JSON:08c7a492674e4d14ad94b328263da942");
//
////        Map<String, String> city_code_map = CacheUtil.get4Map("CITY_CODE_MAP");
//        Object airportCodeMap = redisTemplate.opsForValue().get("AIRPORT_CODE_MAP");
//
//        String cityCodeMap = (String) redisTemplate.opsForValue().get("CITY_CODE_MAP");
//
//        Object sysConfigMap = redisTemplate.opsForValue().get("SYS_CONFIG_MAP");
//        Object basicDataMap = redisTemplate.opsForValue().get("BASIC_DATA_MAP");
//        JSONObject jsonObject = (JSONObject) value;
//        CacheJson cacheJson = jsonObject.toJavaObject(CacheJson.class);
//        CacheUserInfo cacheUserInfo = JSONObject.parseObject(cacheJson.getJson()).toJavaObject(CacheUserInfo.class);
//        return cacheUserInfo;
//    }
}
